package so.sao.code.service.infrastructure.jpa.auditing;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;
import so.sao.code.service.infrastructure.SessionContext;

/**
 * Created by Administrator on 2017/9/13.
 */
@Component
public class UserAuditorAware implements AuditorAware<Long> {
    //    @Autowired
//    HttpServletRequest request;
//    @Autowired
//    JsonMapper jsonMapper;
    @Autowired
    SessionContext context;

    @Override
    public Long getCurrentAuditor() {
//        String value = request.getHeader(so.sao.sso.common.CommonConstants.CURRENT_USER);
//        UserDto user = null;
//        try {
//            user = jsonMapper.fromJson(URLDecoder.decode(value, "UTF-8"), UserDto.class);
//        } catch (Exception e) {
//        }
		if (context == null || context.CURRECT_USER == null) {
			SessionContext ctx = new SessionContext();
			return ctx.CURRECT_USER.getId();
		}
        return context.CURRECT_USER.getId();
    }
}
